$(document).ready(function(){
	  $("#set-option").unbind("click");
	  
	   /*display lang*/
	   var displayLang = $("#display-lang").val();
	   
	   /*leftnav */
	   $("a.d").addClass("nav-select");
	   $(".leftnav a").mouseover(function(){
		   $(this).addClass("bh");
	   });
	   $(".leftnav a").mouseout(function(){
		   $(this).removeClass("bh");
	   }); 
	   $(".leftnav a").click(function(){
		   if(!$(this).hasClass("nav-select")){
			   $(".leftnav a.nav-select").each(function(){
				   $(this).removeClass("nav-select");
			   });
			   $(this).addClass("nav-select");
			   if($(this).hasClass("c")){
				   $(".lang-display-set").hide();
				   $(".lang-prefer-set").show();
			   }else{
				   $(".lang-display-set").show();
				   $(".lang-prefer-set").hide();
			   }
		   }
	   });
	   
	   $("#groupbuttons .sbutton").click(function(){
		   var from = $("#f");
		   if($(".option .box").length>0){
				var sgid=$(".option .box").find("input[name=gselect]:checked");
				if(sgid.length==0){
					 if(displayLang=="en")
						 $.messager.alert('Error','Please select an editing group!','error');
					 else if(displayLang=="zh")
						   $.messager.alert('错误','请选择一个编辑组!','error');
					 return;
				}
				var userName =getUser();
				var gid = sgid.val();
				setGroupByParam(userName,gid);
				if(from.length>0){
					var location = from.val();
					window.location=location;
				}else{
					var location = WEBAPP+"views/index.jsp" ;
					if(lang=="zh"){
						location=location+"?lang=zh" ;
					}
					window.location=location;
				}
		   }else{
			   var paraString;
			   if(from.length>0){
				   paraString = encodeURIComponent(from.val());
			   }else{
				   paraString = "/sview/index.jsp";
				   if(displayLang=="zh"){
					   paraString+=("&lang=zh");
				   }
			   }
			   var location = WEBAPP+"group/gmanage.jsp?from="+paraString;
   			   if(displayLang=="zh")
   				   location = WEBAPP+"group/gmanage.jsp?lang=zh&from="+paraString;
   			   window.location= location;
		   }
	   });
	   
	   $("#groupbuttons .cbutton").click(function(){
		   var from = $("#f");
		   if(from.length>0){
			   var location =from.val();
			   window.location=location;
		   }else{
			   var location = WEBAPP+"views/index.jsp" ;
			   if(lang=="zh"){
	                 location=location+"?lang=zh" ;
               }
			   window.location=location;
		   }		   
	   });
});

function setGroupByParam(userName,groupID){
	var data = {};
	data["user"] = userName;
	data["groupID"] = groupID;
	data = JSON.stringify(data);
	data = ("groupset=" + encodeURIComponent(data));
	$.ajax({
		url:"/sview/setting",
		async : false,
		data : data,
		dataType : "json",
		type : "post"
	});
}

